package org.tloss;

public class Utils {
	public static boolean canMove(Location o, Location n, Status status) {
		int dx = o.getX() - n.getX();
		int dy = o.getY() - n.getY();
		if (dx == 0) {
			if (dy == 0) {
				// OK
				return true;
			} else if (dy > 0) {
				return status.canMoveRight(o.getX(), o.getY())
						&& status.canMoveLeft(o.getX(), o.getY() + 1);
			} else {
				return status.canMoveLeft(o.getX(), o.getY())
						&& status.canMoveRight(o.getX(), o.getY() - 1);
			}
		} else if (dx > 0) {
			return status.canMoveUp(o.getX(), o.getY())
					&& status.canMoveDown(o.getX() + 1, o.getY());
		} else {
			return status.canMoveDown(o.getX(), o.getY())
					&& status.canMoveUp(o.getX() - 1, o.getY());
		}
	}
}
